﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoketPack
{
    class Errors
    {
        public enum ErrorType
        {
            ERROR_CAN_NOT_START_OR_CONNECT_TO_IPC,
            ERROR_CAN_NOT_ASSOCIATE_PROTOCOL,
            ERROR_CAN_NOT_HANDLE_URL_REQUEST,
            ERROR_INVALID_URL_REQUEST
        }

        private enum ErrorLevel
        {
            UNSET,
            WARNING,
            ERROR,
            CRITICAL
        }

        public static void Raise(ErrorType err)
        {
            string msg;
            string caption;
            ErrorLevel lvl = ErrorLevel.UNSET;
            switch (err)
            {
                case ErrorType.ERROR_CAN_NOT_START_OR_CONNECT_TO_IPC:
                    msg = "Unable to communicate with or initialize the RoketPack software service.  The requested software will not be installed.";
                    caption = "Software Installation";
                    lvl = ErrorLevel.CRITICAL;
                    break;
                case ErrorType.ERROR_CAN_NOT_ASSOCIATE_PROTOCOL:
                    msg = "Unable to associate RoketPack with the roket: protocol.  Some internet links may not operate correctly.";
                    caption = "Protocol Association";
                    lvl = ErrorLevel.ERROR;
                    break;
                case ErrorType.ERROR_CAN_NOT_HANDLE_URL_REQUEST:
                    msg = "Unable to handle the requested URL because RoketPack is currently not accepting requests.  Ensure that it is not currently initalizing repositories and try again.";
                    caption = "Request Not Accepted";
                    lvl = ErrorLevel.ERROR;
                    break;
                case ErrorType.ERROR_INVALID_URL_REQUEST:
                    msg = "RoketPack was unable to interpret the requested URL.  Ensure that it is correctly formed and try again.";
                    caption = "Invalid URL";
                    lvl = ErrorLevel.ERROR;
                    break;
                default:
                    msg = "Unable to determine the error message that should be shown.";
                    caption = "Unknown Error";
                    lvl = ErrorLevel.CRITICAL;
                    break;
            }

            // Now handle the error.  For the moment this is just MessageBox.Show.
            switch (lvl)
            {
                case ErrorLevel.CRITICAL:
                    MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    break;
                case ErrorLevel.ERROR:
                    MessageBox.Show(msg, caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    break;
                default:
                    break;
            }
        }
    }
}
